package cn.wujiangbo.controller.app;

import cn.wujiangbo.domain.app.AppSuggestion;
import cn.wujiangbo.result.PageList;
import cn.wujiangbo.service.app.AppSuggestionService;
import cn.wujiangbo.query.app.AppSuggestionQuery;
import cn.wujiangbo.controller.base.BaseController;
import cn.wujiangbo.util.DateUtils;
import cn.wujiangbo.result.JSONResult;
import cn.wujiangbo.result.PageList;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import java.util.Arrays;
import java.util.List;

/**
 * 意见反馈表 API接口
 */
@RestController
@RequestMapping("/appSuggestion")
@Api(value = "/appSuggestion", tags = {"意见反馈表 API接口"})
public class AppSuggestionController extends BaseController{

    @Autowired
    public AppSuggestionService appSuggestionService;

    /**
     * 新增数据到【意见反馈表】
     */
    @PostMapping(value="/save")
    @ApiImplicitParams({
        @ApiImplicitParam(paramType = "body", dataType = "AppSuggestion", name = "appSuggestion", value = "")
    })
    @ApiOperation(value = "新增数据到【意见反馈表】", notes = "新增数据到【意见反馈表】", httpMethod = "POST")
    public JSONResult save(@RequestBody AppSuggestion appSuggestion){
        appSuggestion.setCreateTime(DateUtils.getCurrentLocalDateTime());
        appSuggestion.setCreateUserName(getCurrentUserRealName());
        appSuggestionService.save(appSuggestion);
        return JSONResult.success(true);
    }

    /**
     * 修改【意见反馈表】表数据
     */
    @PostMapping(value="/update")
    @ApiImplicitParams({
        @ApiImplicitParam(paramType = "body", dataType = "AppSuggestion", name = "appSuggestion", value = "")
    })
    @ApiOperation(value = "修改【意见反馈表】表数据", notes = "修改【意见反馈表】表数据", httpMethod = "POST")
    public JSONResult update(@RequestBody AppSuggestion appSuggestion){
        appSuggestion.setUpdateUserName(getCurrentUserRealName());
        appSuggestionService.updateById(appSuggestion);
        return JSONResult.success(true);
    }

    /**
     * 批量删除【意见反馈表】数据
     */
    @PostMapping(value="/batchDelete")
    @ApiImplicitParams({
        @ApiImplicitParam(paramType = "body", dataType = "AppSuggestionQuery", name = "query", value = "")
    })
    @ApiOperation(value = "批量删除【意见反馈表】数据", notes = "批量删除【意见反馈表】数据", httpMethod = "POST")
    public JSONResult batchDelete(@RequestBody AppSuggestionQuery query){
        //批量删除数据库数据
        appSuggestionService.removeByIds(Arrays.asList(query.getIds()));
        return JSONResult.success(true);
    }

    /**
     * 单个删除【意见反馈表】数据
    */
    @ApiImplicitParams({
        @ApiImplicitParam(paramType = "path", dataType = "long", name = "id", value = "")
    })
    @ApiOperation(value = "单个删除【意见反馈表】数据", notes = "单个删除【意见反馈表】数据", httpMethod = "DELETE")
    @DeleteMapping("/singleDelete/{id}")
    public JSONResult batchDelete(@PathVariable("id") Long id){
        //单个删除数据库数据
        appSuggestionService.removeById(id);
        return JSONResult.success(true);
    }

    /**
    * 根据ID查询【意见反馈表】详情数据
    */
    @GetMapping(value = "/{id}")
    @ApiImplicitParams({
        @ApiImplicitParam(paramType = "path", dataType = "long", name = "id", value = "")
    })
    @ApiOperation(value = "根据ID查询【意见反馈表】详情数据", notes = "根据ID查询【意见反馈表】详情数据", httpMethod = "GET")
    public JSONResult get(@PathVariable("id")Long id){
        return JSONResult.success(appSuggestionService.getById(id));
    }

    /**
    * 查询【意见反馈表】所有数据（不分页）
    */
    @GetMapping(value = "/list")
    @ApiOperation(value = "查询【意见反馈表】所有数据（不分页）", notes = "查询【意见反馈表】所有数据（不分页）", httpMethod = "GET")
    public JSONResult list(){
        QueryWrapper<AppSuggestion> queryWrapper = new QueryWrapper();
        queryWrapper.orderByDesc("id");
        List<AppSuggestion> list = appSuggestionService.list(queryWrapper);
        return JSONResult.success(list);
    }

    /**
     * 查询【意见反馈表】数据（分页）
     * @param query 查询对象
     * @return PageList 分页对象
     */
    @PostMapping(value = "/pagelist")
    @ApiImplicitParams({
        @ApiImplicitParam(paramType = "body", dataType = "AppSuggestionQuery", name = "query", value = "查询对象")
    })
    @ApiOperation(value = "查询【意见反馈表】数据（分页）", notes = "查询【意见反馈表】数据（分页）", httpMethod = "POST")
    public JSONResult pagelist(@RequestBody AppSuggestionQuery query){
        Page<AppSuggestion> page = appSuggestionService.selectMySqlPage(query);
        return JSONResult.success(new PageList<>(page.getTotal(), page.getRecords()));
    }

    /***********************************************************************************
    以上代码是自动生成的
    自己写的代码放在下面
    ***********************************************************************************/




}